<layout name="layout" />
<div class="pageheader notab">
	<h1 class="pagetitle">
		<a href="/" class="linkWay">首页/我的卡位策略</a>
		&nbsp;<span class="divider">»</span>&nbsp;
		<a href="#" class="currentWay">我的卡位策略</a>
	</h1>
</div>
<style>
	#con-list-tr tr {
		height: 40px;
	}
</style>
<div clear="all"></div>
<div id="contentwrapper" class="contentwrapper">
	<div id="maincontent">
		<div style="padding-right:10px;width:100%">
			<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
				<thead id="">
				<tr>
					<th width="5%" class="head1">ID</th>
					<th class="head0">卡位测略</th>
					<th width="10%" class="head1">状态</th>
					<th width="10%" class="head0">卡位轮次</th>
					<th width="30%" class="head1">卡位区间</th>
					<th width="15%" class="head0">上一次卡位时间</th>
					<th width="20%" class="head1">操作</th>
				</tr>
				</thead>
				<tbody id="con-list-tr">
				<if condition="$list.rowCount eq 0">
					<tr>
						<td colspan="6">暂无卡位策略</td>
					</tr>
					<else/>
					<volist name="list['res_array']" id="v">
						<tr data-task-id="{$v.tactics_id}">
							<td>{$v.tactics_id}</td>
							<td>
								<a href="/ranking/showTacticsByTacticsId?tactics_id={$v.tactics_id}">{$v.tactics_name}</a>
							</td>
							<if condition="$v.tactics_status eq 1">
								<td class="status_name green">运行中</td>
								<else/>
								<td class="status_name red">停止</td>
							</if>
							<td>{$v.executions}</td>
							<td>
								<if condition="$v.from && $v.to">
									开始:{$v.from|display_date}<br>
									结束:{$v.to|display_date}
								</if>
							</td>
							<td>{$v.tactics_modified_time|display_date}</td>
							<td>
								<a href="/ranking/showTacticsByTacticsId?tactics_id={$v.tactics_id}">详情</a>&nbsp;
								<if condition="$v.tactics_status eq 1">
									<a href="javascript:;" data-status="2" class="status">暂停</a>&nbsp;
									<else/>
									<a href="javascript:;" data-status="1" class="status">开启</a>&nbsp;
								</if>
								<a class="edit" href="/shortcut/ranking_rules?tactics_id={$v.tactics_id}">编辑</a>&nbsp;
								<a href="javascript:;" class="delete" data-id="{$v.tactics_id}">删除</a>
							</td>
						</tr>
					</volist>
				</if>
				</tbody>
			</table>
			<div class="paging-box paging-full" id="page_html" style="display:inline-block;margin-right:20px;">
				{$pageHtml}
			</div>
		</div>
	</div>
</div>
<script>
	var doing = false;
	// 分页跳转
	$(document).on('click', '#page_html li', function() {
		var o = $(this).find("a");
		if(!o.hasClass('active')) {
			var new_page = parseInt(o.data('page'));
			if(new_page === +new_page)
				window.location.href = "/ranking/show?pageNow=" + new_page;
		}

	});

	// 分页跳转
	$(document).on('click', '#page_html .to_page', function() {
		var o = $(this).parent('.form'),
				v = parseInt(o.find('.input').val());
		if(v === +v)
			window.location.href = "/ranking/show?pageNow=" + v;
	});

	// 调整状态
	$(document).on('click', '.status', function() {
		msg.closeAll();
		var o = $(this),
				tactics_id = o.parents('tr').data('task-id'),
				status = parseInt(o.attr('data-status'));
		msg.load();
		setTimeout(function() {
			wt.ajax('/ranking/playOrStopTactics', 'post',{
				tactics_id : tactics_id,
				tactics_status : status
			}, function(r) {
				msg.closeAll('loading');
				var oE = $.parseJSON(r);
				if(oE.data.code == 0) {
					o.parents('tr').find('.status_name').text(status == 1? '运行中' : '暂停');
					o.attr('data-status', status == 1 ? 2 : 1);
					o.parents('tr').find('.status_name').attr('class', status == 1 ? 'status_name green' : 'status_name red');
					o.text(status == 1 ? '暂停' : '开启');
				}
				msg.msg(oE.data.msg);
			})
		}, 1000);
	});

	// 删除卡位
	$(document).on('click', '.delete', function() {
		msg.closeAll();
		var o = $(this),
				tactics_id = o.data('id');
		msg.msg('确定要删除卡位策略吗？', {
			time : 0,
			btn: ['确定', '取消'],
			yes: function(index){
				if(doing)
					return false;
				doing = true;
				delete_kawei(tactics_id, o);
			}
		})
	});

	function delete_kawei (tactics_id, obj) {
		wt.ajax('/ranking/delTacticsByTacticsId', 'post', {
			tactics_id : tactics_id
		}, function(r) {
			var oE = $.parseJSON(r);
			msg.msg(oE.data.msg);
			if(oE.data.code == 1)
				obj.parents('tr').remove();
			doing = false;
		})
	}

</script>